package leecode

import (
	"strconv"
	"strings"
)

func isIsomorphic(s string, t string) bool {
	newS := newString2(s)
	newT := newString2(t)
	return newS == newT
}

// 解析字符串
func newString2(s string) string {
	index := 1
	str := strings.Split(s, "")
	wordMap := make(map[string]string, len(s))
	for _, key := range str {
		_, ok := wordMap[key] //坚持key键是否存在
		if !ok {
			wordMap[key] = strconv.Itoa(index)
			index++
		}
	}
	newStr := make([]string, 0)
	for _, value := range str {
		newStr = append(newStr, wordMap[value])
	}
	newString := strings.Join(newStr, "")
	return newString
}
